package gui;

import java.awt.BorderLayout;
import javax.swing.*;

import game.Game;

public class Gui {

	public final int SIZEX = Game.XSIZE * Game.FIELDWIDTH;
	public final int SIZEY = Game.YSIZE * Game.FIELDWIDTH;

	//Adjust weird java window size
	public final int XPREFIX = 4;
	public final int YPREFIX = 23;
	public final int XSUFFIX = 4;
	public final int YSUFFIX = 4;

	//Reference to the Game class
	private Game game;

	//References to the gui components
	private JFrame frame;
	private GridPanel panel;
	private MenuBar menuBar;
	private JFrame newGameFrame;
	private NewGamePanel newGamePanel;

	//var to store the ai type
	//private String ai;

	public Gui(Game g)
	{
		this.game = g;

		//Create the gui components
		this.frame = new JFrame();
		this.panel = new GridPanel(this);
		this.menuBar = new MenuBar(this);

		//Set windowsize, title and default close operation
		this.frame.setTitle("Four in a row");
		this.frame.setSize(
				this.SIZEX + this.XPREFIX + this.XSUFFIX,
				30 + this.SIZEY + this.YPREFIX + this.YSUFFIX);
		this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		//Center the window
		this.frame.setLocationRelativeTo(null);

		//Add the menu
		this.frame.setJMenuBar(menuBar.getMenuBar());
		this.frame.setLayout(new BorderLayout());
		this.frame.setResizable(false);

		//Insert the panel
		this.frame.add(panel, BorderLayout.CENTER);

		
		
		//Build the new game window
		this.newGameFrame = new JFrame();
		this.newGameFrame.setTitle("New game");
		this.newGameFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		this.newGameFrame.setSize(300, 260);
		this.newGameFrame.setLocationRelativeTo(null);
		this.newGamePanel = new NewGamePanel(this.game, this.newGameFrame);
		this.newGameFrame.add(this.newGamePanel);
		
		

		//And finally make the window visible
		this.frame.setVisible(true);
	}
	
	public void displayNewGameMenu()
	{
		this.newGameFrame.setVisible(true);
	}
	
	public Game getGame()
	{
		return this.game;
	}

	public void repaint()
	{
		this.frame.repaint();
	}
	
}
